package Demo_type2;

/**
 * @className: SingletonTest
 * @description: 静态内部类来实现单例模式 推荐使用
 * @author: Jng
 * @date: 2022/7/19
 **/
public class SingletonTest {

    public static void main(String[] args) {
        Singletion instance = Singletion.getInstance();
        Singletion instance1 = Singletion.getInstance();
        System.out.println(instance==instance1);

    }
}

class Singletion{
    private  Singletion() {
    }
    private static class SingletonInstance{
        private static final Singletion INSTANCE=new Singletion();
    }
    public static synchronized Singletion getInstance(){
        return SingletonInstance.INSTANCE;
    }
}